<template>
  <el-upload class="upload-demo"
             :action="ATactionUrl"
             :http-request="uploadFile"
             :show-file-list="false"
             :headers="headers"
             accept=".xls, .xlsx">
    <el-button type="text"
               icon="el-icon-upload2">导入文件</el-button>
  </el-upload>
</template>

<script>
// import { templateJson } from './upload.json'
import { quotation } from "@/api/index";
export default {
  name: 'UploadQuotation',
  data () {
    return {
      headers: {
        Authorization: "Bearer " + sessionStorage.getItem("token"),
      },
      ATactionUrl: ""
    }
  },
  methods: {
    uploadFile (file) {
      let form = new FormData();
      form.append("file", file.file);
      this.upload(form);
    },
    upload (form) {
      this.$emit('importLoading', true)
      quotation.readExcel(form).then(response => {
        if (response?.code === 0) {
          const { data } = response
          const importJson = data?.template
          this.$emit('importData', importJson)
        } else {
          this.$emit('importLoading', false)
          this.$message.error(response?.message);
        }
      })
      // setTimeout(() => {
      //   const importJson = templateJson
      //   console.log('importJson', importJson)
      //   this.$emit('importData', importJson)
      // }, 1500)
    }
  }
}
</script>

<style>
</style>